There should be some C source code in the Mag5/ drawer under the name 'Euclid.c'. It's all text based, and you don't need any off the Amiga Includes. You can view the code clicking here, if you like.
This program just uses Euclid's algorithm to calculate the highest common factor of two numbers.
What is Euclid's Algorithm? I hear you say. Well, first of all, you start off with your two numbers (a and b in the program). We get these from the user with the scanf function. Npw for the algorithm:
1 - We then stick these into a[1] and a[2] respectively, so that a[1] is greater or equal to a[2] (I know that isn't in the program - more
on that later!)
2 - Let n=2
3 - If a[n+1] divides a[n] exactly, then STOP, a[n+1] is the highest common factor.
4 - Let a[n+2] be the remainder of a[n] divided by a[n+1]
5 - Increase n by 1
6 - Goto Step 3
And that's it. As I said the program doesn't check whether a[1] or a[2] is bigger. Try running the program, and enter a bigger number second - it still works! I'm not entirely sure way this is, probably related to the way the modulus function (%) works, but as it does work, there is no need to check which number is bigger.
Talking of the modulus, this is how we do remainder division. Look at the line:
A[n+2]=A[n] % A[n+1];
This divides A[n] by A[n+1] and stores the remainder in A[n].
For example, 11 divided by 3 equals 3, remainder 2. Therefore, 11 % 3 = 2. If the remainder is 0, then it divides exactly, so we can stop.
Anyway, that's enough for now. See you next issue with some more C code (maybe).
Mark